# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=proxenet
pkgver=712.67fc6b5
pkgrel=12
groups=('blackarch' 'blackarch-webapp' 'blackarch-proxy' 'blackarch-sniffer')
pkgdesc='THE REAL hacker friendly proxy for web application pentests.'
arch=('x86_64' 'aarch64')
url='https://github.com/hugsy/proxenet'
license=('GPL2')
depends=('mbedtls' 'lua' 'ruby' 'python3' 'python2')
makedepends=('git' 'cmake')
source=("git+https://github.com/hugsy/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cd $pkgname

  sed -i 's|"/opt/${PROGNAME}"|"/usr/"|' CMakeLists.txt

  git submodule init
  git submodule update
}

build() {
  cd $pkgname

  cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .

  make

  #make -C keys
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 755 "$pkgname-control-web.py" \
    "$pkgdir/usr/bin/$pkgname-control-web"
  install -Dm 755 "$pkgname-control-cli.py" \
    "$pkgdir/usr/bin/$pkgname-control-cli"
  install -Dm 644 "$pkgname.1" "$pkgdir/usr/share/man/man1/$pkgname.1"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  cp -a proxenet keys "$pkgdir/usr/share/$pkgname/"
  #cp -a proxenet keys proxenet-plugins "$pkgdir/usr/share/proxenet"
  cp -a docs/* "$pkgdir/usr/share/doc/$pkgname/"

  install -dm 755 "$pkgdir/usr/share/$pkgname/$pkgname-plugins/autoload"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
exec /usr/share/$pkgname/$pkgname -x /usr/share/$pkgname/$pkgname-plugins \\
  -c /usr/share/$pkgname/keys/$pkgname.crt \\
  -k /usr/share/$pkgname/keys/$pkgname.key "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

